﻿#include "componentlist.h"
#include "ui_componentlist.h"
#include <QDebug>
#include <QDirIterator>
#include <QLibrary>
#include <QProcess>

void CompenentList::AddDes(QString des)
{
    QStringList deslist = des.split("####");
    foreach(QString funcinfo,deslist){
        QStringList list = funcinfo.split("@@@@");
        if(list.size()<2){
            continue;
        }
        m_desMap[list[0]] = list[1];
        ui->listWidget->addItem(list[0]);
    }
}

CompenentList::CompenentList(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::CompenentList)
{
    ui->setupUi(this);
    this->setWindowTitle(QStringLiteral("插件使用帮助"));
    AddDes("TaiJiPlugins");
}

CompenentList::~CompenentList()
{
    delete ui;
}

void CompenentList::on_listWidget_itemClicked(QListWidgetItem *item)
{
    ui->textBrowser->setText(m_desMap[item->text()]);
}

void CompenentList::on_listWidget_itemDoubleClicked(QListWidgetItem *item)
{
    QStringList args;
    args << "-call" << item->text().toUtf8();
    QProcess *process = new QProcess;
    qDebug() << QApplication::applicationDirPath().replace("x86_64","x86")+"/TaiJi.exe" << args;
    process->startDetached(QApplication::applicationDirPath().replace("x86_64","x86")+"/TaiJi.exe",args);
    process->waitForStarted();
}
